import java.util.Arrays;
import java.util.Scanner;

class Test {
        public static void rotate(int[] nums, int k) {
            if(k > nums.length) {
                k %= nums.length;
            }
            int[] array = new int[nums.length];
            for(int i = 0;i < k;i++) {
                array[i] = nums[nums.length-k+i];
            }
            for(int i = k;i < nums.length;i++) {
                array[i] = nums[i-k];
            }
            System.out.print("[");
            for(int i = 0;i < array.length;i++) {
                if(i != array.length - 1) {
                    System.out.print(array[i] + ",");
                } else {
                    System.out.print(array[i]);
                }
            }
            System.out.printf("]");
            //array = Arrays.copyOfRange(nums, 0, nums.length);//将调用方法的原数组正确修改，这是创建了一个新的数组对象,array指向改变
            System.arraycopy(array, 0, nums, 0, nums.length);//这是对于原数组修改
        }

    public static void main(String[] args) {
        int[] nums = {1,2,3,4,5,6,7};
        int k = 3;
        rotate(nums,k);
    }
}